package ch.ethz.fcl.metrobuzz.render.od;

import org.lwjgl.opengl.Display;

import ch.ethz.fcl.metrobuzz.MBContainer;
import ch.ethz.fcl.metrobuzz.render.AbstractRenderer;
import ch.ethz.fcl.metrobuzz.render.interchange.mrt.MRTInterchangeRender;
import ch.ethz.fcl.metrobuzz.render.od.map_view.MapViewer;
import ch.ethz.fcl.metrobuzz.spatialindex.object2d.Rectangle;

public class ODRender extends AbstractRenderer {
	private MBContainer container;

	private boolean initialized = false;

	private MRTInterchangeRender mrt = null;

	private MapViewer mapView = null;

	public ODRender(MBContainer container) {
		this.container = container;
	}

	public void update() {
		if (!initialized) {
			init();
			initialized = true;
		}

		render();
	}

	protected void render() {
		Rectangle bound = container.getViewer().getProjection()
				.getBound(0, 0, Display.getWidth(), Display.getHeight(), 0);

		mrt.render(bound);

		mapView.render();
	}

	public void init() {
		if (container.getData() == null) {
			initialized = false;
			return;
		}

		if (container == null) {
			initialized = false;
			return;
		}

		mrt = new MRTInterchangeRender(this.container, container.getData()
				.getSGInfo().getSGInterchange());

		mapView = new MapViewer(this.container);
	}

	public MapViewer getMapView() {
		return mapView;
	}
}
